#include<bits/stdc++.h>
using namespace std;
deque<int> q;
vector<int> edges[100];
int n,m;
signed main()
{
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		int a,b;
		cin>>a>>b;
		edges[a].push_back(b);
	}
	q.push_back(1);
	while(!q.empty())
	{
		int sz=q.size();
		
		while(sz--)
		{
			int u=q.front();
			cout<<u<<" ";
			q.pop_front();
			for(int i=0;i<edges[u].size();i++)
			{
				q.push_back(edges[u][i]);
			}
		}
		cout<<endl;
	}
	return 0;
}
